package pkg

import (
	"fmt"
	"product/global/model"
	"time"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func MysqlConn() {
	var err error
	model.DB, err = gorm.Open(mysql.Open("root:89B158B4DAFE6F5461878D26EA49B100@tcp(14.103.158.217:3306)/9.9exam?charset=utf8&parseTime=True&loc=Local"))
	if err != nil {
		panic(err)
	}
	db, err := model.DB.DB()
	if err != nil {
		panic(err)
	}
	db.SetMaxIdleConns(10)
	db.SetMaxOpenConns(100)
	db.SetConnMaxLifetime(time.Hour)
	fmt.Println("mysql connect success")
}
